﻿using ReflectionStudio.Components.UserControls;
using ReflectionStudio.Core.Events;
using System;
using System.ComponentModel;
using System.Data;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Collections.Generic;
using System.Threading;
using System.Diagnostics;
using System.Windows.Documents;
using System.Printing;
namespace WPFExcelReport
{
    public partial class AFSVA06
    {
        #region ==IsVA02===========
        public static readonly DependencyProperty IsVA02Property = DependencyProperty.Register("IsVA02",
            typeof(bool), typeof(AFSVA06),
            new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnIsVA02Changed));
        public bool IsVA02
        {
            get
            {
                return (bool)GetValue(IsVA02Property);
            }
            set
            {
                SetValue(IsVA02Property, value);
            }
        }
        private static void OnIsVA02Changed(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as AFSVA06;
            if (src != null)
            {
                src.IsVA02 = (bool)e.NewValue;
            }
        }

        #endregion

        #region ==IsVA06===========
        public static readonly DependencyProperty IsVA06Property = DependencyProperty.Register("IsVA06",
            typeof(bool), typeof(AFSVA06),
            new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnIsVA06Changed));
        public bool IsVA06
        {
            get
            {
                return (bool)GetValue(IsVA06Property);
            }
            set
            {
                SetValue(IsVA06Property, value);
            }
        }
        private static void OnIsVA06Changed(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as AFSVA06;
            if (src != null)
            {
                src.IsVA06 = (bool)e.NewValue;
            }
        }

        #endregion

        #region ==IsVA09===========
        public static readonly DependencyProperty IsVA09Property = DependencyProperty.Register("IsVA09",
            typeof(bool), typeof(AFSVA06),
            new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnIsVA09Changed));
        public bool IsVA09
        {
            get
            {
                return (bool)GetValue(IsVA09Property);
            }
            set
            {
                SetValue(IsVA09Property, value);
            }
        }
        private static void OnIsVA09Changed(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as AFSVA06;
            if (src != null)
            {
                src.IsVA09 = (bool)e.NewValue;
            }
        }

        #endregion

        VAFSVA06 vm;
        public AFSVA06()
        {
            vm = new VAFSVA06();
            DataContext = vm;
            InitializeComponent();
            this.Name = "Article";
            ReSetTab();
            IsVA06 = true;
            SetUp();
        }
        /// <summary> 

        /// This method creates a dynamic FlowDocument. You can add anything to this 

        /// FlowDocument that you would like to send to the printer 

        /// </summary> 

        /// <returns></returns> 

        private FlowDocument CreateFlowDocument()

        {

            // Create a FlowDocument 

            FlowDocument doc = new FlowDocument();



            // Create a Section 

            Section sec = new Section();



            // Create first Paragraph 

            Paragraph p1 = new Paragraph();

            // Create and add a new Bold, Italic and Underline 

            Bold bld = new Bold();

            bld.Inlines.Add(new Run("First Paragraph"));

            Italic italicBld = new Italic();

            italicBld.Inlines.Add(bld);

            Underline underlineItalicBld = new Underline();

            underlineItalicBld.Inlines.Add(italicBld);

            // Add Bold, Italic, Underline to Paragraph 

            p1.Inlines.Add(underlineItalicBld);



            // Add Paragraph to Section 

            sec.Blocks.Add(p1);



            // Add Section to FlowDocument 

            doc.Blocks.Add(sec);



            return doc;

        }

        private void PrintSimpleTextButton_Click(object sender, RoutedEventArgs e)

        {

            // Create a PrintDialog 

            PrintDialog printDlg = new PrintDialog();



            // Create a FlowDocument dynamically.  

            FlowDocument doc = CreateFlowDocument();

            doc.Name = "FlowDoc";



            // Create IDocumentPaginatorSource from FlowDocument 

            IDocumentPaginatorSource idpSource = doc;



            // Call PrintDocument method to send document to printer 

            printDlg.PrintDocument(idpSource.DocumentPaginator, "Hello WPF Printing.");

        }

        private void SetUp()
        {
            //默认注释随客户不同而不同，所以放在这里
            //根据01-，02-，03-等等对备注类型进行分类。分类方法可以依据客户不同自己定义，主要用于报表和显示。例如01如果代表成份，则可以在打印时处理。保存在TXTKON表的某个自duang
            List<string> deftxt = new List<string>();
            deftxt.Add("01-备注:");
            cMaster.DEFWSTXT = deftxt;
            deftxt = new List<string>();
            deftxt.Add("00-please type your remark after remove this:");
            cMaster.DEFTXT = deftxt;
            cMaster.VALBTYP = "VALBTYP";
            cMaster.IsExtProd = true;
            /*
            {
                System.IO.Directory.CreateDirectory("T:\\IntexReport");
            }
            if (!System.IO.Directory.Exists("T:\\IntexReport\\Images"))
            {
                System.IO.Directory.CreateDirectory("T:\\IntexReport\\Images");
            }*/
            //if (!System.IO.Directory.Exists("T:"))
            //{
            //    /*string COMM = "";
            //    COMM = "net use T: //192.168.1.16/IntexReport Tissu!@# /USER:administrator ";
            //    RunCmd(COMM);*/
            //    MessageBox.Show("请先建立T盘映射，就看到图片！");
            //}
            //cMaster.IMAGEPATH = "T:\\Images";
            /*if (cMaster.MV.IsITX)
            {
                cMaster.IMAGEPATH = "d:\\Images";
            }*/
        }
        public static string RunCmd(string command)
        {
            Process p = new Process();
            p.StartInfo.WorkingDirectory = "c:\\";
            p.StartInfo.FileName = "cmd.exe"; //程序名
            p.StartInfo.Arguments = "/c " + command;
            p.StartInfo.UseShellExecute = false;
            p.StartInfo.RedirectStandardInput = true;
            p.StartInfo.RedirectStandardOutput = true;
            p.StartInfo.RedirectStandardError = true; //重定向错误输出
            p.StartInfo.CreateNoWindow = true; //不显示窗口

            p.Start();
            return p.StandardOutput.ReadToEnd();
        }
        private void ReSetTab()
        {
            IsVA02 = false;
            IsVA06 = false;
            IsVA09 = false;
        }

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            try
            {
                if (DesignerProperties.GetIsInDesignMode(this))
                    return;
                if (IsLoaded)
                    return;
                IsLoaded = true;

            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
            return;

        }

        private void ShowVA02Command(object sender, RoutedEventArgs e)
        {
            ReSetTab();
            IsVA02 = true;
        }

        private void ShowVA06Command(object sender, RoutedEventArgs e)
        {
            ReSetTab();
            IsVA06 = true;
        }

        private void ShowVA09Command(object sender, RoutedEventArgs e)
        {
            ReSetTab();
            IsVA09 = true;
        }
    }
}
